package com.example.controller;

import com.example.domain.MeetingApplication;
import com.example.domain.SysMeetingroom;
import com.example.service.IMeetingApplicationService;
import com.example.service.ISysMeetingroomService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议室申请管理Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/application")
public class MeetingApplicationController extends BaseController
{
    @Autowired
    private IMeetingApplicationService meetingApplicationService;
    @Autowired
    private ISysMeetingroomService sysMeetingroomService;

    /**
     * 查询会议室申请管理列表
     */
    @RequiresPermissions("day:application:list")
    @GetMapping("/list")
    public TableDataInfo list(MeetingApplication meetingApplication)
    {
        startPage();
        List<MeetingApplication> list = meetingApplicationService.selectMeetingApplicationList(meetingApplication);
        return getDataTable(list);
    }

    /**
     * 导出会议室申请管理列表
     */
    @RequiresPermissions("day:application:export")
    @Log(title = "会议室申请管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingApplication meetingApplication)
    {
        List<MeetingApplication> list = meetingApplicationService.selectMeetingApplicationList(meetingApplication);
        ExcelUtil<MeetingApplication> util = new ExcelUtil<MeetingApplication>(MeetingApplication.class);
        util.exportExcel(response, list, "会议室申请管理数据");
    }

    /**
     * 获取会议室申请管理详细信息
     */
    @RequiresPermissions("day:application:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingApplicationService.selectMeetingApplicationById(id));
    }

    /**
     * 新增会议室申请管理
     */
    @RequiresPermissions("day:application:add")
    @Log(title = "会议室申请管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingApplication meetingApplication)
    {
        return toAjax(meetingApplicationService.insertMeetingApplication(meetingApplication));
    }

    /**
     * 修改会议室申请管理
     */
    @RequiresPermissions("day:application:edit")
    @Log(title = "会议室申请管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingApplication meetingApplication)
    {
        return toAjax(meetingApplicationService.updateMeetingApplication(meetingApplication));
    }

    /**
     * 删除会议室申请管理
     */
    @RequiresPermissions("day:application:remove")
    @Log(title = "会议室申请管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meetingApplicationService.deleteMeetingApplicationByIds(ids));
    }
    /**
     * 查询启用的会议室
     */
    @GetMapping("/meetinglist")
    public TableDataInfo list(SysMeetingroom sysMeetingroom)
    {
        startPage();
        sysMeetingroom.setStatus( 1 );
        List<SysMeetingroom> list = sysMeetingroomService.selectSysMeetingroomList(sysMeetingroom);
        return getDataTable(list);
    }


}
